# frozen_string_literal: true

class RulesController < ApplicationController
  def index
    render json: RuleService.search(params)
  end

  def show
    render json: RuleService.show(params.require(:id))
  end

  def create
    render json: RuleService.create(rule_params.permit!)
  end

  def update
    render json: RuleService.update(params[:id], rule_params.permit(:name, :description, :status))
  end

  def destroy
    render json: RuleService.delete(params.require(:id))
  end

  def validate_by_uuid
    render json: RuleService.validate_by_uuid(params.require(:uuid))
  end

  def fire
    render json: RuleService.fire(params.require(:uuid), params.require(:inputs))
  end

  private

  def rule_params
    params.require(:schema)
  end
end
